<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/5/13
 * Time: 9:37
 */

namespace Admin\Controller;
use Think\Controller;

class LoginController extends Controller
{
    private $admin='';
    private $business='';

    function __construct(){
        parent::__construct();
        $this->admin=D("Admin");
        $this->business=D("Seller");
    }

    function index(){
        layout(false);

        if ($_POST){
            $cond['name'] = $_POST['username'];
            $cond['password'] = $_POST['password'];
            $yanG = $this->admin->where($cond)->find();

            if ($yanG == true)    // 此用户存在  将用户名存入session
            {
                session("AdminUser", $yanG['name']);    // 将用户名存入session
                $yanGOne=explode(";",$yanG['auth']);
                session("AdminAuth",$yanGOne);     // 将权限写入session
                $this->assign("AdminUser", $yanG['name']);
                $this->redirect("Goods/index");
            }else{     // 此用户不存在
                redirect('index', 3, "username error...");
            }
        }else{
            $this->display("Login/login");    // 去登录
            exit;
        }
    }

    function outLogin()   // 登出的操作
    {
        session("AdminUser",NULL);
        session("AdminAuth",NULL);
        $this->redirect("Goods/indez");
    }

    /*
     * 商户登录入口
     * */
    function sellerLogin()
    {
        layout(false);
        if ($_POST){
            $cond['username'] = $_POST['username'];
            $cond['password'] = $_POST['password'];
            $yanG = $this->business->where($cond)->find();

            if ($yanG['id'] != '')    // 此用户存在  将用户名存入session
            {
                session("seller", $yanG['nick']);    // 将用户名存入session
                session("sellerID",$yanG['id']);   // 将卖家的ID 存储到session里面

                    $this->redirect('Business/index');
            }else{     // 此用户不存在
                echo "error...";
                exit;
            }
        }else{
            $this->display("login");    // 去登录
            exit;
        }
    }

    function outSellerLogin()
    {
        session("seller",NULL);
        session("sellerID",NULL);
        $this->redirect("Goods/indez");
    }
}